class webtts {
    text = "";
    // 创建 SpeechSynthesisUtterance 对象
    speechUtterance = null
    // 创建 SpeechSynthesis 对象
    synthesis = null
    constructor() {
        this.synthesis = window.speechSynthesis;
    }
    eventHandler() {
        // 开始语音合成
        this.speechUtterance.onstart = function (event) {
            console.log('Speech synthesis started.');
        };
        // 结束语音合成
        // this.speechUtterance.onend = function (event) {
        //     console.log('Speech synthesis ended.');
        // };
        // 暂停语音合成
        // this.speechUtterance.onpause = function (event) {
        //     console.log('Speech synthesis paused.');
        // };
        // 恢复语音合成
        // this.speechUtterance.onresume = function (event) {
        //     console.log('Speech synthesis resumed.');
        // };
        // 分段语音合成
        // this.speechUtterance.onboundary = function (event) {
        //     console.log('Speech boundary reached at character index ' + event.charIndex + '.');
        // };
        // 声音改变事件
        // this.speechSynthesis.onvoiceschanged = function (event) {
        //     console.log('Voices changed.',event)
        // }
    }
    // 启动语音合成
    speak(text) {
        this.text = text;
        this.speechUtterance = new SpeechSynthesisUtterance(this.text);
        this.eventHandler()
        this.synthesis.speak(this.speechUtterance);
    }
    // 停止语音合成
    cancel() {
        this.synthesis.cancel(this.speechUtterance);
    }
    // 暂停语音合成
    pause() {
        this.synthesis.pause(this.speechUtterance);
    }
    // 继续语音合成
    resume() {
        this.synthesis.resume(this.speechUtterance);
    }
}


// // 创建 SpeechRecognition 对象
// var recognition = new window.SpeechRecognition();

// // 设置语音识别的事件处理函数

// // 开始语音识别
// recognition.onstart = function (event) {
//     console.log('Speech recognition started.');
// };

// // 结束语音识别
// recognition.onend = function (event) {
//     console.log('Speech recognition ended.');
// };

// // 识别到语音结果
// recognition.onresult = function (event) {
//     var transcript = event.results[0][0].transcript;
//     console.log('Recognized speech: ' + transcript);
// };

// export function getText() {
//     // 启动语音识别
//     recognition.start();
// }

export default webtts